package com.example.administrator.myapplication.Presenter;

import com.example.administrator.myapplication.Bean.AjaxResult;
import com.example.administrator.myapplication.Bean.Label;
import com.example.administrator.myapplication.Model.ILabelModel;
import com.example.administrator.myapplication.Model.LabelModel;
import com.example.administrator.myapplication.View.Fragment.ILabelView;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Administrator on 2019/10/14 0014.
 */

public class LabelPresenter implements ILabelPresenter,ILabelListener{
    private ILabelModel iLabelModel;
    private ILabelView iLabelView;

    public LabelPresenter(ILabelView iLabelView) {
        this.iLabelModel = new LabelModel();
        this.iLabelView = iLabelView;
    }

    @Override
    public void addLabel(Label label) {
        iLabelModel.addLabel(label,this);
    }

    @Override
    public void getLabels() {
        iLabelModel.getLabels(this);
    }

    @Override
    public void labelList(List<HashMap> labels) {
        iLabelView.showLables(labels);
    }

    @Override
    public void success(AjaxResult ajaxResult) {
        if(ajaxResult.getCode()==AjaxResult.SUCCESS_CODE)
            iLabelView.showSuccess(ajaxResult.getMsg());
        else
            iLabelView.showError(ajaxResult.getMsg());
    }

    @Override
    public void error(String error) {
        iLabelView.showError(error);
    }
}

